package hash;

import java.util.HashSet;

/**
 * @author way
 * @create 2025-02-07 10:29
 */
public class _349_intersection {
    public int[] intersection(int[] nums1, int[] nums2) {
        if (nums1 == null || nums1.length == 0 || nums2 == null || nums2.length == 0) {
            return new int[0];
        }

        HashSet<Integer> set = new HashSet<>();
        HashSet<Integer> resSet = new HashSet<>();

        for (int i : nums1) {
            set.add(i);
        }

        for (int i : nums2) {
            if (set.contains(i)){
                resSet.add(i);
            }
        }

        return resSet.stream().mapToInt(x ->x).toArray();
    }
}
